# -*- coding: utf-8 -*-
'''工具脚本，将strokes文件夹下所有笔画的Z轴从-1~1重映射为0-1(因为中间修改过一次Z轴意义)'''
import os
import re
import json
import sys
reload(sys)
sys.setdefaultencoding('utf8')

stroke_names = []
file_list = os.listdir('./calligraphy_lib/strokes')
for f_name in file_list:
    if re.search('.\.json', f_name) != None:
        json_obj = None
        with open('./calligraphy_lib/strokes/'+f_name, 'r') as f:
            json_obj = json.loads(f.read())
        for i in range(len(json_obj['stroke_points'])):
            json_obj['stroke_points'][i][2] = -(json_obj['stroke_points'][i][2]-1.0)/2.0
        with open('./calligraphy_lib/strokes/'+f_name, 'w') as f:
            f.write(json.dumps(json_obj, indent=4, ensure_ascii=False))
